package org.fcy.controller;

import org.fcy.domain.po.Result;
import org.fcy.utils.AliOssUtil;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.UUID;

@RestController
@CrossOrigin
public class CommonController {
    //文件上传
    @PostMapping("/upload")
    public Result<String> uploadFile(@RequestParam("file") MultipartFile file) throws IOException {
        String originalFilename = file.getOriginalFilename();
        String fileName= UUID.randomUUID().toString() +"."+originalFilename;
        String uploadFile = AliOssUtil.uploadFile(fileName, file.getInputStream());
        return Result.success(uploadFile);
    }

}
